/**
 *
 */
package wsepForum.ui.swing.outerPanels;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.concurrent.ExecutionException;

import javax.swing.JButton;

import wsepForum.network.client.GUIController;
import wsepForum.ui.swing.SetSwitcher;
import wsepForum.ui.swing.innerPanels.AInnerPanel;
import wsepForum.ui.swing.innerPanels.LoginPanel;
import wsepForum.ui.swing.innerPanels.RegisterPanel;
import wsepForum.ui.swing.workers.ForumWorker;


public class GuestPanel extends AOuterPanel {


	/**
	 *
	 */
	private static final long serialVersionUID = 3721401401585018609L;

	/**
	 *
	 */
	public GuestPanel(GUIController connection, SetSwitcher switcher) {
		super(connection,switcher);
		addLoginButton();
		addRegisterButton();
	}

	protected void addLoginButton() {
		JButton loginButton = this.buttonFactory("Login", 639, 42, 97, 40);
		loginButton.addActionListener(new ActionListener(){
			@Override
			public void actionPerformed(ActionEvent e) {
				ForumWorker<AInnerPanel> worker = new ForumWorker<AInnerPanel>(connection){
					@Override
					protected AInnerPanel doInBackground() throws Exception {
						LoginPanel loginPanel = new LoginPanel(GuestPanel.this);
						return loginPanel;
					}
					@Override
					public void done(){
						try {
							swapInnerPanel(get());
						} catch (InterruptedException e) {
							e.printStackTrace();
						} catch (ExecutionException e) {
							e.printStackTrace();
						}
					}
				};
				worker.execute();
			}
		});
	}

	protected void addRegisterButton() {

		JButton registerButton = this.buttonFactory("Register", 532, 42, 97, 40);
		registerButton.addActionListener(new ActionListener(){
			@Override
			public void actionPerformed(ActionEvent e) {
				ForumWorker<AInnerPanel> worker = new ForumWorker<AInnerPanel>(connection){
					@Override
					protected AInnerPanel doInBackground() throws Exception {
						return new RegisterPanel(GuestPanel.this);
					}
					@Override
					public void done(){
						try {
							swapInnerPanel(get());
						} catch (InterruptedException e) {
							e.printStackTrace();
						} catch (ExecutionException e) {
							e.printStackTrace();
						}
					}
				};
				worker.execute();
			}
		});
	}
}
